# _*_ coding: utf-8 _*_
# @Time : 2024-01-19 21:30
# @Author : wf

# 安装jsonpath : pip install jsonpath

import jsonpath
import json


obj = json.load(open('store.json', 'r+', encoding='utf-8'))
# 所有的作者
# print(obj)

# author_list = jsonpath.jsonpath(obj, '$.store.book[*].author')
# print(author_list)

# 所有的作者
# author_list = jsonpath.jsonpath(obj, '$..author')
# print(author_list)

# store下面的所有子节点
# a_list = jsonpath.jsonpath(obj, '$.store.*')
# print(a_list)

# price_list = jsonpath.jsonpath(obj, '$.store..price')
# print(price_list)

# 第三本书
# book = jsonpath.jsonpath(obj, '$..book[2]')
# print(book)


# 最后一本书
# book = jsonpath.jsonpath(obj, '$..book[(@.length - 1)]')
# print(book)


# 前两本书
# book_list = jsonpath.jsonpath(obj, '$..book[0,1]')
# book_list = jsonpath.jsonpath(obj, '$..book[:2]')
# print(book_list)

# 包含isbn的书
# book_list = jsonpath.jsonpath(obj, '$..book[?(@.isbn)]')
# print(book_list)

# 超过10元的书
book_list = jsonpath.jsonpath(obj, '$..book[?(@.price > 10)]')
print(book_list)
